package com.thread;


/**
 * @author :admin
 * @description: “非线程安全”问题存在于“实例变量”中，如果是方法内部的私有变量，则不存在“非
 * 线程安全”问题，所得结果也就是“线程安全”的了
 * @create date: 2019/4/3 16:04
 */
public class ThreadDemoVariableTest {

    public static void main(String[] args) {
        ThreadStu numRef = new ThreadStu();
        ThreadA athread = new ThreadA(numRef);
        athread.start();
        ThreadB bthread = new ThreadB(numRef);
        bthread.start();
    }
}

class ThreadA extends Thread {
    ThreadStu threadStu;

    public ThreadA(ThreadStu threadStu) {
        this.threadStu = threadStu;
    }

    @Override
    public void run() {
        threadStu.addNum("a");
    }
}

class ThreadB extends Thread {
    ThreadStu threadStu;

    public ThreadB(ThreadStu threadStu) {
        this.threadStu = threadStu;
    }

    @Override
    public void run() {
        threadStu.addNum("b");
    }
}